package com.softserveinc.moviedbapp.parser;

import android.util.Log;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class JSONHelper {

	private static final String TAG = JSONHelper.class.getSimpleName();

	public static String convertStreamToString(final InputStream is) throws IOException {

		BufferedReader reader = new BufferedReader(new InputStreamReader(is), 2048);
		StringBuilder sb = new StringBuilder();

		String line = null;
		try {
			while ((line = reader.readLine()) != null) {
				sb.append(line + "\n");
			}
		} catch (IOException e) {
			Log.e(TAG, "unable to read json input stream", e);
			throw new IOException();
		} finally {
			try {
				is.close();
			} catch (IOException e) {
				Log.e(TAG, "unable to close input stream", e);
			}
		}
		return sb.toString();
	}
}
